package com.zhugang.week05;

import java.util.HashMap;
import java.util.Map;

/**
 * @program algorithms
 * @description: wordsFrequency
 * @author: chanzhugang
 * @create: 2022/07/08 15:23
 */
public class WordsFrequency {


    /**
     * 面试题 16.02 单词频率
     *
     * @param book
     */

    Map<String, Integer> map = new HashMap<>();

    public WordsFrequency(String[] book) {
        for (String s : book) {
            int count = 1;
            if (map.containsKey(s)) {
                count += map.get(s);
            }
            map.put(s, count);
        }
    }

    public int get(String word) {
        if (!map.containsKey(word)) {
            return 0;
        }
        return map.get(word);
    }
}